<template>
  <div>
    <el-table :data="payInfoList">
      <el-table-column prop="trackingNumber" label="查询号"></el-table-column>
      <el-table-column label="出库理由">
        <template slot-scope="scope">
          <div v-if="scope.row.payType==0">发货出库</div>
          <div v-if="scope.row.payType==1">退货出库</div>
        </template>
      </el-table-column>
      <el-table-column prop="ptime" label="入库时间"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-dropdown split-button type="primary" @click="openCheckpayDetailInfo_dialog(scope.row.id)">
            查看详情
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <el-button size="mini" type="primary" @click="audit(scope.row.id,1)">允许通过</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button size="mini" type="danger" @click="audit(scope.row.id,2)">拒绝通过</el-button>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageno"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
    <div>
      <payDetailInfo_dialog ref="payDetailInfo_dialog"></payDetailInfo_dialog>
    </div>
  </div>
</template>

<script>
    import payDetailInfo_dialog from "./payDetailInfo_dialog";

    export default {
        name: "checkPayInfo",
        data(){
          return{
            payInfoList:[],
            pageno: 1,
            pagesize: 5,
            total: 1
          }
        },
        methods:{
          getData(){
            let payInfo={
              isCheck:0,//等待审核
              isDelete:0//正常
            };
            let params=new URLSearchParams();
            params.append("pageno", this.pageno);
            params.append("pagesize", this.pagesize);
            Object.keys(payInfo).forEach(item=>{
              params.append(item,payInfo[item]);
            })
            //异步，分页查询
            this.$axios.get("payInfo/payInfo.action",{params:params}).
            then((response)=> {   //异步调用成功执行
              //将查询到的数据存入对象数组中
              this.payInfoList=response.data.records;
              this.total = response.data.total;
            });
          },
          openCheckpayDetailInfo_dialog(pid){
            this.$refs.payDetailInfo_dialog.dialogVisible=true;
            this.$nextTick(item=>{
              this.$refs.payDetailInfo_dialog.getData(pid);
            })
          },
          audit(id,isCheck){
            let payInfo={
              id:id,
              isCheck:isCheck
            }
            //调用异步，进行审核
            this.$axios.put("payInfo/audit.action",payInfo)
              .then(res=>{
                if(res.data.x){
                  this.$message.success(res.data.msg);
                }else {
                  this.$message.error(res.data.msg);
                }
                //重新查询一次数据
                this.getData();
              })
              .catch(err=>{
                this.$message.warning(err);
                alert(err);
              })
          },
          handleSizeChange(val) {
            //每页范围
            this.pagesize = val;
            this.getData();
          },
          handleCurrentChange(val) {
            //当前页
            this.pageno = val;
            this.getData();
          }
        },
        created() {
          this.getData();
        },
        components:{
          payDetailInfo_dialog
        }
    }
</script>

<style scoped>

</style>
